<!--
 * @Author: your name
 * @Date: 2021-11-30 14:24:46
 * @LastEditTime: 2021-11-30 15:19:45
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \front-end-algorithm\datasandstructorAndalorithms-js\二维数组求解.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二维数组求解</title>
</head>

<body>


    <p>
        [
        [1 ,2 ,3],
        [4, 5 ,6],
        [7, 8 ,9]
        ]
    </p>

    <script>
        let arr = [
            [1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]
        ];
        let findResult = (arr, tag) => {
            if (arr && arr.length) {
                let row = arr[0].length;
                let col = -1;
                //找出最后一列的数据和当前和当前数据作比较，
                let newArr = [];
                for (let i = 0; i < arr.length; i++) {
                    let index = arr[i].length - 1;//这里是否要做数组矩阵的行列比较，以至于在最后取值时候减少循环
                    let firstNum = arr[i][index];
                    //newArr.push(lastNum);
                    console.log('输出第一行：', firstNum, '----------', i);
                    if (firstNum >= tag) {
                        col = i;
                        break;
                    }
                }
                //如果没有这个列就不存在这样的数据
                if (col == -1) {
                    return false;
                } else {
                    //tag存在于 arr[i]行
                    //只是找出了大于的然后遍历 arr[i]行，如果存在就找出否则就不存在
                    let length = col;
                    let preArr = arr[length];
                    let isResult = false;
                    for (let j = 0; j < preArr.length; j++) {
                        let res = preArr[j];
                        if (res == tag) {
                            isResult = true;
                            break
                        }
                    }
                    if (isResult) {
                        return true;
                    }
                    return false;
                }
            } else {
                return false;
            }

        };
        let myArr = [

            [1, 2, 3, 4, 5, 6],
            [71, 81, 91, 101, 111, 121],
            [122, 132, 142, 152, 162, 172, 182]

        ]
        console.log(findResult(myArr, 11))
    </script>

</body>

</html>